Optimize exact XTRIM MAXLEN zero#4161
Conversation
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
📝 WalkthroughWalkthrough
ChangesStream trimming
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/unit/type/stream.tcl (1)
722-732: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winExercise multiple radix-tree nodes.
Two entries do not guarantee multiple nodes, so this test does not prove that the entire tree is cleared. Force a small
stream-node-max-entries, add entries across several nodes, then assertXRANGEis empty andradix-tree-keysis zero before restoring the configuration.Suggested test expansion
r DEL mystream - r XADD mystream 1-0 f v - r XADD mystream 2-0 f v - assert_equal 2 [r XTRIM mystream MAXLEN = 0] + r config set stream-node-max-entries 1 + for {set j 1} {$j <= 3} {incr j} { + r XADD mystream $j-0 f v + } + assert_equal 3 [r XTRIM mystream MAXLEN = 0] assert_equal 1 [r EXISTS mystream] set reply [r XINFO STREAM mystream] assert_equal 0 [dict get $reply length] - assert_equal "2-0" [dict get $reply last-generated-id] + assert_equal {} [r XRANGE mystream - +] + assert_equal 0 [dict get $reply radix-tree-keys] + assert_equal "3-0" [dict get $reply last-generated-id] assert_equal "0-0" [dict get $reply recorded-first-entry-id] + r config set stream-node-max-entries 100🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/type/stream.tcl` around lines 722 - 732, Update the test XTRIM with MAXLEN 0 keeps an empty stream key to temporarily set stream-node-max-entries to a small value, add enough entries to span multiple radix-tree nodes, and restore the configuration afterward. After trimming, retain the existing stream metadata assertions and also verify XRANGE returns no entries and radix-tree-keys is zero.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/unit/type/stream.tcl`:
- Around line 722-732: Update the test XTRIM with MAXLEN 0 keeps an empty stream
key to temporarily set stream-node-max-entries to a small value, add enough
entries to span multiple radix-tree nodes, and restore the configuration
afterward. After trimming, retain the existing stream metadata assertions and
also verify XRANGE returns no entries and radix-tree-keys is zero.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0313e46e-71fb-4439-8f7e-82236d05c6c8
📒 Files selected for processing (2)
src/t_stream.ctests/unit/type/stream.tcl
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #4161 +/- ##
============================================
+ Coverage 76.82% 76.85% +0.03%
============================================
Files 162 162
Lines 81433 81441 +8
============================================
+ Hits 62561 62594 +33
+ Misses 18872 18847 -25
🚀 New features to boost your workflow:
|
|
@enjoy-binbin any concerns do you see? should we merge? |
|
I don't have any concerns. Yes, we can merge it. |
Exact
XTRIM key MAXLEN = 0removes every stream entry while retaining the stream key and its metadata. The generic path removes radix-tree nodes individually and repeatedly re-positions its iterator, even though the final entry tree must be empty.This change adds a fast path for exact scenario.
XTRIM MAXLEN = 0Found this fast path while debugging with Codex!